package com.smbms.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smbms.dao.BillMapper;
import com.smbms.pojo.Bill;
import com.smbms.service.BillService;
import com.smbms.util.BillPage;
import com.smbms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BillServiceImpl implements BillService {
    @Autowired  //注入属性，在spring容器中找到BillMapper的实现类进行注入
    BillMapper billMapper;

    @Override
    public int addBill(Bill bill) {
        return billMapper.addBill(bill);
    }

    @Override
    public Bill checkByBillCode(String billCode) {
        return billMapper.checkByBillCode(billCode);
    }

    @Override
    public int delBill(Integer id) {
        return billMapper.delBill(id);
    }

    @Override
    public Bill findById(Integer id) {
        return billMapper.findById(id);
    }

    @Override
    public int checkByBillCodeUpd(String billCode, String self) {
        return billMapper.checkByBillCodeUpd(billCode, self);
    }

    @Override
    public int updBill(Bill bill) {
        return billMapper.updBill(bill);
    }

    @Override
    public PageResult findPage(BillPage billPage) {
        PageHelper.startPage(billPage.getPage(),billPage.getSize());
        Page<Bill> bills = billMapper.findPage(billPage);

        //获取列表
        List<Bill> billList = bills.getResult();
        //获取数量
        long total = bills.getTotal();
        return new PageResult(total,billList);
    }
}
